package com.ruoyi.purchase.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.purchase.domain.PurchaseTrace;
import com.ruoyi.purchase.service.IPurchaseTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * purchaseTraceController
 * 
 * @author kevinness
 * @date 2025-01-31
 */
@RestController
@RequestMapping("/PurchaseTrace")
public class PurchaseTraceController extends BaseController
{
    @Autowired
    private IPurchaseTraceService purchaseTraceService;

    /**
     * 查询purchaseTrace列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PurchaseTrace purchaseTrace)
    {
        startPage();
        List<PurchaseTrace> list = purchaseTraceService.selectPurchaseTraceList(purchaseTrace);
        return getDataTable(list);
    }

    /**
     * 导出purchaseTrace列表
     */
    @Log(title = "purchaseTrace", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchaseTrace purchaseTrace)
    {
        List<PurchaseTrace> list = purchaseTraceService.selectPurchaseTraceList(purchaseTrace);
        ExcelUtil<PurchaseTrace> util = new ExcelUtil<PurchaseTrace>(PurchaseTrace.class);
        util.exportExcel(response, list, "purchaseTrace数据");
    }

    /**
     * 获取purchaseTrace详细信息
     */
    @GetMapping(value = "/{orderNo}")
    public AjaxResult getInfo(@PathVariable("orderNo") String orderNo)
    {
        return success(purchaseTraceService.selectPurchaseTraceByOrderNo(orderNo));
    }

    /**
     * 新增purchaseTrace
     */
    @Log(title = "purchaseTrace", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchaseTrace purchaseTrace)
    {
        return toAjax(purchaseTraceService.insertPurchaseTrace(purchaseTrace));
    }

    /**
     * 修改purchaseTrace
     */
    @Log(title = "purchaseTrace", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchaseTrace purchaseTrace)
    {
        return toAjax(purchaseTraceService.updatePurchaseTrace(purchaseTrace));
    }

    /**
     * 删除purchaseTrace
     */
    @Log(title = "purchaseTrace", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderNos}")
    public AjaxResult remove(@PathVariable String[] orderNos)
    {
        return toAjax(purchaseTraceService.deletePurchaseTraceByOrderNos(orderNos));
    }
}
